var express = require('express');
var router = express.Router();
let  service  = require("../service/typeinfoService");

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});
router.get("/list",async (req,res,next)=>{
    let  result  =  await  service.query({});
    res.json({
        code:200,
        list:result
    })
})
router.post("/add",async (req,res,next)=>{
    let  {type,img} = req.body;
    //取值
    let result =  await service.add([{type,img}]); 
    //把数据放到数据库
    res.json({
        code:200,
        msg:"新增成功",
        data:result
    })
})
router.delete("/del",async (req,res,next)=>{ //删除的接口
    let  {id} = req.body;//获取编号
    await  service.del({_id:id});
    res.json({
        code:200,
        msg:"删除成功"
    })
})

module.exports = router;
